package com.xzmd.md_city.controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author:Corday
 * @Date:2021/09/14/19:58
 * 全局异常处理
 */
@ControllerAdvice
public class MyException {
    @ExceptionHandler(value = Exception.class)
    public  String exceptionHandler(Model model, Exception e){
        //还可以用HttpServletRequest,不能用Map
        System.out.println("异常:"+e.getMessage());
        model.addAttribute("msg",e.getMessage());
        //req.setAttribute("msg",e.getMessage());
        return "page/error";
    }
}
